<?php
/**
 * common repository file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2019/12/21
 * Time: 10:19
 */
 
 namespace HiCommon\Repository;

//use HiCommon\Model\ShopUser;

use Illuminate\Support\Facades\DB;

class ShopUserRepository extends BaseRepository
{
    public function base_model(){
        return new \HiCommon\Model\ShopUser();
    }

    /**
     * 获取登录基本信息
     *
     * @param $n_id
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function find_one_login($n_id){
        $arr_option = [
          'with'=>['shop_base'],
//          'with'=>['shop_base'],
        ];
        return self::base_find_one($n_id,$arr_option);
    }


    /**
     * 根据条件查询一条数据
     */
    public function get_where_one(array $where = [], $arr_field = ['*'])
    {
        return \HiCommon\Model\ShopUser::where($where)->select($arr_field)->first();
    }

    /**
     * 根据条件查询一条数据
     */
    public function get_where_one_with(array $where = [], $arr_field = ['*'] , $with = [] )
    {
        return \HiCommon\Model\ShopUser::with( $with )->where($where)->select($arr_field)->first();
    }



    /**
     * 修改一条数据
     *
     * @param array $arr_input
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function edit_one(array $arr_input)
    {
        return \HiCommon\Model\ShopUser::where('shop_id', $arr_input['shop_id'])->update($arr_input);
    }

    /**
     * 分页获取数据
     *
     * @param array $arr_search
     * @param array $arr_option
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function get_search_list($arr_search = [],$arr_option = [])
    {
        return self::base_model()
                   ->where(
                     function ($query)
                     use($arr_search) {
                         $n_shop_id = intval($arr_search['shop_id']);
                         if($n_shop_id > 0){
                             $query->where('shop_id',$n_shop_id);
                         }
                         $s_search_type = str_trim($arr_search['search_type']);
                         $s_key_word = str_trim($arr_search['key_word']);
                         if(!(empty($s_search_type) || empty($s_key_word) )){
                             $query->where($s_search_type, 'like', '%'.$s_key_word.'%');
                         }
                     })
                   ->commonpage($arr_option);
    }

}